package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.entity.NodisturbSwitchReply;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:58 2021/9/1
 * @Description
 */
public class AnalyzeNoDisturbSwitch implements AnalyticalData {
    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,V4,CLASSSWITCH,174444,1,174725,A,2250.2153,N,11391.6210,E,1.49,0,020621,FFFFDFFF
        //解密
        String[] split = parseCommand(originalData);
        String imei = split[1];
        String commandNumber = split[4];
        String switchFlag=split[5];//免打扰设置的开关，1-开 0-关
        String time = split[6];//指令回复的时间（时分秒）
        String lat = split[8];
        String lng = split[10];
        String speed = split[12];
        String orientation = split[13];
        String date = split[14];//年月日
        String deviceStatus = split[15];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        NodisturbSwitchReply nodisturbSwitchReply = new NodisturbSwitchReply();
        nodisturbSwitchReply.setCommandNumber(commandNumber);
        nodisturbSwitchReply.setDeviceDate(date);
        nodisturbSwitchReply.setImei(imei);
        nodisturbSwitchReply.setDeviceDate(deviceStatus);
        nodisturbSwitchReply.setSwitchFlag(Integer.parseInt(switchFlag));
        nodisturbSwitchReply.setDeviceTime(time);
        LocationData mqLocationData = new LocationData();
        mqLocationData.setOrientation(Integer.parseInt(orientation));
        mqLocationData.setSpeed(Double.parseDouble(speed));
        mqLocationData.setLatitude(list.get(1));
        mqLocationData.setLongitude(list.get(0));
        nodisturbSwitchReply.setLocationData(mqLocationData);
        return structureMessage(Constants.REPLY,Constants.CMD_SET_NO_DISTURB_SWITCH,false,"",nodisturbSwitchReply);
    }
}
